/**
 * 好友模块
 **/
package com.kitchen.ui.controls
{
	import com.kitchen.KitchenEvent;
	import com.kitchen.model.Vo.AccountVo;
	import com.kitchen.ui.button.RefreshButton;
	import com.kitchen.ui.button.RightinButton;
	import com.kitchen.ui.button.SearchButton;
	import com.kitchen.ui.controls.friends.List;
	import com.kitchen.ui.controls.friends.button.FlowerButton;
	import com.kitchen.ui.controls.friends.button.GFriendButton;
	import com.kitchen.ui.controls.friends.button.HamburButton;
	import com.kitchen.ui.controls.friends.button.IceButton;
	import com.kitchen.ui.controls.friends.button.InviteButton;
	import com.kitchen.ui.controls.friends.button.RandtoButton;
	import com.kitchen.ui.controls.friends.icon.ChainIcon;
	import com.kitchen.ui.controls.friends.icon.EmployIcon;
	import com.kitchen.ui.controls.friends.icon.FriendBoxBg;
	import com.kitchen.ui.controls.friends.icon.WorkIcon;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	public class FriendsBar extends Sprite
	{
		public var h:Number;
		public var w:Number;
		private var state:int;
		private var shoper:Object;
		private var shop:Object;
		private var searchTf:TextField;
		private var mainSkin:BitmapData;
		private var rightinButton:RightinButton;
		private var list:List;
		private var inited:Boolean;
		
		public function FriendsBar(mainSkin:BitmapData, shoper:Object, shop:Object)
		{
			super();
			this.mainSkin = mainSkin;
			this.shoper = shoper;
			this.shop = shop;
			this.state = -1;
			this.x = 750;
			this.inited = false;
			this.layout();
		}
		
		private function layout():void{
			var bg:FriendBoxBg = new FriendBoxBg(this.mainSkin);
			this.addChild(bg);
			rightinButton = new RightinButton(this.mainSkin);
			rightinButton.name = 'rightin';
			rightinButton.x = 18;
			rightinButton.y = 165;
			rightinButton.rotation = 180;
			rightinButton.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(rightinButton);
		}
		
		private function init():void{
			this.searchTf = new TextField();
			this.searchTf.type = TextFieldType.INPUT;
			this.searchTf.text = '输入好友的昵称';
			this.searchTf.width = 88;
			this.searchTf.height = 18;
			//this.searchTf.border = true;
			var tff:TextFormat = new TextFormat();
			tff.font = '黑体';
			tff.size = 12;
			tff.color = 0xb7b3a7;
			tff.align = TextFormatAlign.LEFT;
			this.searchTf.setTextFormat(tff);
			this.searchTf.x = 48;
			this.searchTf.y = 8;
			this.searchTf.addEventListener(FocusEvent.FOCUS_IN, function(fe:FocusEvent):void{
				if(fe.target.text == '输入好友的昵称'){
					fe.target.textColor = 0x333333;
					fe.target.text = '';
				}
			});
			this.searchTf.addEventListener(FocusEvent.FOCUS_OUT, function(fe:FocusEvent):void{
				if(fe.target.text == ''){
					fe.target.textColor=0xb7b3a7;
					fe.target.text = '输入好友的昵称';
				}
			});
			this.addChild(this.searchTf);
			
			var searchButton:SearchButton = new SearchButton(this.mainSkin);
			searchButton.name = 'search';
			searchButton.x = 136;
			searchButton.y = 7;
			searchButton.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(searchButton);
			
			var freshButton:RefreshButton = new RefreshButton(this.mainSkin);
			freshButton.name = 'refresh';
			freshButton.x = 170;
			freshButton.y = 7;
			freshButton.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(freshButton);
			
			var gfbtn:GFriendButton = new GFriendButton(this.mainSkin, '<span class="h">好友</span> <span class="c">10/200</span>');
			gfbtn.x = 36;
			gfbtn.y = 29;
			this.addChild(gfbtn);
			
			var ice:IceButton = new IceButton(this.mainSkin);
			var ham:HamburButton = new HamburButton(this.mainSkin);
			var work:WorkIcon = new WorkIcon(this.mainSkin);
			var workBtn:Sprite = new Sprite();
			workBtn.addChild(work);
			var flower:FlowerButton = new FlowerButton(this.mainSkin);
			var employ:EmployIcon = new EmployIcon(this.mainSkin);
			var emBtn:Sprite = new Sprite();
			emBtn.addChild(employ);
			var chain:ChainIcon = new ChainIcon(this.mainSkin);
			var chainBtn:Sprite = new Sprite();
			chainBtn.addChild(chain);
			ice.y = ham.y = workBtn.y = flower.y = emBtn.y = chainBtn.y = 60;
			ham.x = 36;
			ice.x = 60;
			flower.x = 83;
			emBtn.x = 110;
			workBtn.x = 135;
			chainBtn.x = 160;
			chainBtn.useHandCursor = emBtn.useHandCursor = workBtn.useHandCursor = true;
			chainBtn.buttonMode = emBtn.buttonMode = workBtn.buttonMode = true;
			ice.name = 'ice';
			ice.addEventListener(MouseEvent.CLICK, onClickHandle);
			ham.name = 'ham';
			ham.addEventListener(MouseEvent.CLICK, onClickHandle);
			flower.name = 'flower';
			flower.addEventListener(MouseEvent.CLICK, onClickHandle);
			emBtn.name = 'employ';
			emBtn.addEventListener(MouseEvent.CLICK, onClickHandle);
			chainBtn.name = 'chain';
			chainBtn.addEventListener(MouseEvent.CLICK, onClickHandle);
			workBtn.name = 'work';
			workBtn.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(ice);
			this.addChild(ham);
			this.addChild(flower);
			this.addChild(emBtn);
			this.addChild(chainBtn);
			this.addChild(workBtn);
			
			var invite:InviteButton = new InviteButton(this.mainSkin);
			invite.y = 359;
			invite.x = 38;
			invite.name = 'invite';
			invite.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(invite);
			
			var randto:RandtoButton = new RandtoButton(this.mainSkin);
			randto.y = 359;
			randto.x = 120;
			randto.name = 'randto';
			randto.addEventListener(MouseEvent.CLICK, onClickHandle);
			this.addChild(randto);
			
			list = new List(this.mainSkin, this.shoper, this.shop);
			list.x = 40;
			list.y = 85;
			list.addEventListener(KitchenEvent.FRIEND, visitHandle);
			this.addChild(list);
		}
		
		private function visitHandle(ke:KitchenEvent):void{
			trace('bar');
			this.dispatchEvent(ke);
		}
		
		private function onClickHandle(me:MouseEvent):void{
			//this.app.debug(me.target.name);
			var cname:String = me.target.name;
			switch(cname){
				case 'rightin':
				this.state*=-1;
				if(this.state == 1){
					if(!this.inited){
						this.init();
						this.inited = true;
					}
					this.rightinButton.rotation = 0;
					this.x = 580;
				}else if(this.state == -1){
					this.rightinButton.rotation = 180;
					this.x = 750;
				}
				break;
				default:
				trace(cname);
				break;
			}
		}
		
	}
}